#include "response.h"
#include <sstream>

// 构造函数，默认初始化为200 OK
Response::Response() : statusCode(200), statusMessage("OK") {
    // 设置默认的Content-Type
    headers["Content-Type"] = "text/plain";
}

// 将响应转换为字符串格式
std::string Response::toString() const {
    std::ostringstream oss;
    
    // 响应行
    oss << "HTTP/1.1 " << statusCode << " " << statusMessage << "\r\n";
    
    // 响应头
    for (const auto& header : headers) {
        oss << header.first << ": " << header.second << "\r\n";
    }
    
    // 添加Content-Length头
    oss << "Content-Length: " << body.size() << "\r\n";
    
    // 头和体的分隔符
    oss << "\r\n";
    
    // 响应体
    oss << body;
    
    return oss.str();
}
